<template>
  <view class="goods-item" @click="gotoDetail(goods.goods_id)">
    <!-- 商品左侧图片区域 -->
    <view class="goods-item-left">
      <slot name="radio" />
      <image :src="goods.goods_small_logo || imgUrl" class="goods-pic" />
    </view>
    <!-- 商品右侧信息区域 -->
    <view class="goods-item-right ">
      <!-- 商品标题 -->
      <text class="goods-name">{{ goods.goods_name }}</text>
      <!-- 商品价格 -->
      <view class="goods-price-number">
        <text class="goods-price">￥{{ goods.goods_price | tofixed }}</text>
        <slot name="number" />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    goods: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      imgUrl: require('@/static/logo.png')
    }
  },
  filters: {
    // toFixed可以保留几位小数
    tofixed (v) {
      return v.toFixed(2)
    }
  },
  methods: {
    // 跳转到详情页
    gotoDetail (goods_id) {
      uni.navigateTo({
        url: '/subpkg/goods-detail/index?goods_id=' + goods_id
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    margin-right: 5px;
    display: flex;
    align-items: center;
    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
      margin-left: 5px;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .goods-name {
      font-size: 13px;
    }

    .goods-price-number {
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
    .goods-price {
      font-size: 16px;
      color: #c00000;
    }
  }
}
</style>
